package icu.qx.gbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import icu.qx.gbs.domain.GbsGoodClass;
import icu.qx.gbs.service.IGbsGoodClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物品分类Controller
 *
 * @author ruoyi
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/gbs/class")
public class GbsGoodClassController extends BaseController {
    @Autowired
    private IGbsGoodClassService gbsGoodClassService;

    /**
     * 查询物品分类列表 分页
     */
    @RequiresPermissions("gbs:class:list")
    @GetMapping("/list")
    public TableDataInfo list(GbsGoodClass gbsGoodClass) {
        startPage();
        List<GbsGoodClass> list = gbsGoodClassService.selectGbsGoodClassList(gbsGoodClass);
        return getDataTable(list);
    }

    /**
     * 查询物品分类列表 所有
     */
    @RequiresPermissions("gbs:class:list")
    @GetMapping("/all")
    public R<List<GbsGoodClass>> all(GbsGoodClass gbsGoodClass) {
        List<GbsGoodClass> list = gbsGoodClassService.selectGbsGoodClassList(gbsGoodClass);
        return R.ok(list);
    }

    /**
     * 导出物品分类列表
     */
    @RequiresPermissions("gbs:class:export")
    @Log(title = "物品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbsGoodClass gbsGoodClass) {
        List<GbsGoodClass> list = gbsGoodClassService.selectGbsGoodClassList(gbsGoodClass);
        ExcelUtil<GbsGoodClass> util = new ExcelUtil<GbsGoodClass>(GbsGoodClass.class);
        util.exportExcel(response, list, "物品分类数据");
    }

    /**
     * 获取物品分类详细信息
     */
    @RequiresPermissions("gbs:class:query")
    @GetMapping(value = "/{gcId}")
    public AjaxResult getInfo(@PathVariable("gcId") Long gcId) {
        return success(gbsGoodClassService.selectGbsGoodClassByGcId(gcId));
    }

    /**
     * 新增物品分类
     */
    @RequiresPermissions("gbs:class:add")
    @Log(title = "物品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbsGoodClass gbsGoodClass) {
        return toAjax(gbsGoodClassService.insertGbsGoodClass(gbsGoodClass));
    }

    /**
     * 修改物品分类
     */
    @RequiresPermissions("gbs:class:edit")
    @Log(title = "物品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbsGoodClass gbsGoodClass) {
        return toAjax(gbsGoodClassService.updateGbsGoodClass(gbsGoodClass));
    }

    /**
     * 删除物品分类
     */
    @RequiresPermissions("gbs:class:remove")
    @Log(title = "物品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{gcIds}")
    public AjaxResult remove(@PathVariable Long[] gcIds) {
        return toAjax(gbsGoodClassService.deleteGbsGoodClassByGcIds(gcIds));
    }
}
